<?php

use kzo\base\widgets\ui\common\menu\Menu;
use kzo\rbac\helpers\MenuHelper;
use kzo\rbac\widgets\AuthMenu;

/* @var $this \yii\web\View */
/* @var $content string */

$callback = function ($menu) {
    $data = json_decode($menu['data'], true);
    $items = $menu['children'];
    $return = [
        'label' => $menu['name'],
        'url' => [$menu['route']],
    ];
    // 处理我们的配置
    if ($data) {
        // visible
        isset($data['visible']) && $return['visible'] = $data['visible'];
        // icon
        isset($data['icon']) && $data['icon'] && $return['icon'] = $data['icon'];
        // other attribute e.g. class...
        $return['options'] = $data;
    }
    // 没配置图标的显示默认图标
    (!isset($return['icon']) || !$return['icon']) && $return['icon'] = 'fa fa-circle-notch';
    $items && $return['items'] = $items;
    return $return;
};

// $items1 = [
//     ['label' => Yii::t('app.c2', 'Menu'), 'options' => ['class' => 'header']],
//     ['label' => Yii::t('app.c2', 'Dashboard'), 'icon' => 'fa fa-circle-notch', 'url' => ['/']],
//     [
//         'label' => Yii::t('app.c2', 'Logistics'), 'icon' => 'fa fa-circle-notch', 'url' => ['#'], 'options' => ['class' => 'treeview'],
//         'items' => [
//             ['label' => Yii::t('app.c2', 'Region'), 'icon' => 'fa fa-circle-notch', 'url' => ['/logistics/region']],
//         ]
//     ],
//     [
//         'label' => Yii::t('app.c2', 'System'),
//         'icon' => 'fa fa-circle-notch',
//         'url' => ['#'],
//         'options' => ['class' => 'treeview'],
//         'items' => [
//             [
//                 'label' => Yii::t('app.c2', 'Common Resource'), 'icon' => 'fa fa-circle-notch', 'url' => ['#'], 'options' => ['class' => 'treeview'],
//                 'items' => [
//                     ['label' => Yii::t('app.c2', '{s1} Management', ['s1' => Yii::t('app.c2', 'Attachment')]), 'icon' => 'fa fa-circle-notch', 'url' => ['/sys/common-resource/attachment'],],
//                     ['label' => Yii::t('app.c2', '{s1} Management', ['s1' => Yii::t('app.c2', 'Config')]), 'icon' => 'fa fa-circle-notch', 'url' => ['/sys/common-resource/config/default/index']],
//                 ]
//             ],
//             [
//                 'label' => Yii::t('app.c2', 'Security'),
//                 'icon' => 'fa fa-circle-notch',
//                 'url' => ['#'],
//                 'visible' => Yii::$app->user->can('P_System'),
//                 'options' => ['class' => 'treeview'],
//                 'items' => [
//                     ['label' => Yii::t('app.c2', 'Users'), 'icon' => 'fa fa-circle-notch', 'url' => ['/user/admin']],
//                     ['label' => Yii::t('app.c2', 'Route'), 'icon' => 'fa fa-circle-notch', 'url' => ['/rbac/route']],
//                     ['label' => Yii::t('app.c2', 'Permission'), 'icon' => 'fa fa-circle-notch', 'url' => ['/rbac/permission']],
//                     ['label' => Yii::t('app.c2', 'Role'), 'icon' => 'fa fa-circle-notch', 'url' => ['/rbac/role']],
//                     ['label' => Yii::t('app.c2', 'Rule'), 'icon' => 'fa fa-circle-notch', 'url' => ['/rbac/rule']],
//                     ['label' => Yii::t('app.c2', 'Menu'), 'icon' => 'fa fa-circle-notch', 'url' => ['/rbac/menu']],
//                 ]
//             ],
//         ]
//     ],
//     ['label' => Yii::t('app.c2', 'Sign out'), 'icon' => 'fa fa-sign-out-alt', 'url' => ['/user/logout']],
// ];

$items = MenuHelper::getAssignedMenu(Yii::$app->user->id, null, $callback);

?>
<style>
    #kv-gs-form {
        padding: 10px
    }
</style>
<aside class="main-sidebar">

    <section class="sidebar">

        <form class="form-inline kv-navbar-form" id="kv-gs-form" role="search">
            <div class="input-group">
                <input id="kv-gs-query" type="text" class="form-control" placeholder="Search Menus ..."
                       autocomplete="off">
                <span class="input-group-btn input-group-append" title="Submit"><button type="submit"
                                                                                        class="btn btn-outline-success"><i
                                class="fa fa-search"></i></button></span>
            </div>
        </form>

        <?=

        Menu::widget([
                'options' => ['class' => 'sidebar-menu', "data-widget" => "tree"],
                'linkTemplate' => '<a href="{url}" {targetPlaceHolder}>{icon} {label}</a>',
                // 'items' => $items1,
                'items' => $items
            ]
        ); ?>

    </section>

</aside>
